package com.jiutong.meipengdai.utils;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.widget.EditText;
import android.widget.TextView;

/**
 * 作用:
 * Created by 78 on 2017/7/3.
 */

public class TimerUtil {

    private  EditText et;
    private CountDownTimer timer;
    private TextView tv;


    public  TimerUtil( TextView tv) {
        this.tv = tv;
    }

    public  TimerUtil(TextView tv, EditText et) {
        this.tv = tv;
        this.et = et;
    }
    //设置倒计时
    public void setCountTimer(){
        timer = new CountDownTimer(60000, 1000) {

            @Override
            public void onTick(long millisUntilFinished) {
                tv.setTextColor(Color.parseColor("#808080"));
                tv.setText(millisUntilFinished / 1000 + "秒后重新获取");
            }

            @Override
            public void onFinish() {
                // TODO Auto-generated method stub
                tv.setTextColor(Color.parseColor("#f09738"));
                tv.setText("重新获取验证码");
            }
        };
    }

    //设置倒计时
    public void setCountTimerEt(){
        timer = new CountDownTimer(60000, 1000) {

            @Override
            public void onTick(long millisUntilFinished) {
                tv.setTextColor(Color.parseColor("#808080"));
                tv.setText(millisUntilFinished / 1000 + "秒后重新获取");
            }

            @Override
            public void onFinish() {
                // TODO Auto-generated method stub
                tv.setTextColor(Color.parseColor("#f09738"));
                tv.setText("重新获取验证码");
                et.setText("");
            }
        };
    }

    public void startTimer(){
        timer.start();
    }
}
